// 商店系统 - 管理商店物品和购买逻辑
class ShopSystem {
    constructor(scene) {
        this.scene = scene;
        this.purchasedItems = new Set(); // 记录已购买的物品
        
        this.shopItems = [
            // === 消耗品 ===
            {
                id: 'health_potion',
                name: '生命药水',
                description: '恢复50点生命值',
                cost: 20,
                unlimited: true,
                category: 'consumable',
                effect: () => {
                    this.scene.playerStats.health = Math.min(
                        this.scene.playerStats.maxHealth,
                        this.scene.playerStats.health + 50
                    );
                    if (this.scene.uiSystem) {
                        this.scene.uiSystem.updateHealthText(this.scene.playerStats.health);
                    }
                }
            },
            {
                id: 'mana_potion',
                name: '法力药水',
                description: '恢复30点法力值',
                cost: 15,
                unlimited: true,
                category: 'consumable',
                effect: () => {
                    this.scene.playerStats.mana = Math.min(
                        this.scene.playerStats.maxMana,
                        this.scene.playerStats.mana + 30
                    );
                }
            },
            {
                id: 'energy_drink',
                name: '能量饮料',
                description: '恢复40点能量值',
                cost: 18,
                unlimited: true,
                category: 'consumable',
                effect: () => {
                    this.scene.playerStats.energy = Math.min(
                        this.scene.playerStats.maxEnergy,
                        this.scene.playerStats.energy + 40
                    );
                }
            },
            {
                id: 'full_heal',
                name: '完全治愈',
                description: '恢复所有生命值、法力值和能量值',
                cost: 50,
                unlimited: true,
                category: 'consumable',
                effect: () => {
                    this.scene.playerStats.health = this.scene.playerStats.maxHealth;
                    this.scene.playerStats.mana = this.scene.playerStats.maxMana;
                    this.scene.playerStats.energy = this.scene.playerStats.maxEnergy;
                    if (this.scene.uiSystem) {
                        this.scene.uiSystem.updateHealthText(this.scene.playerStats.health);
                    }
                }
            },

            // === 核心属性升级 ===
            {
                id: 'max_health_up',
                name: '生命强化',
                description: '最大生命值 +30',
                cost: 60,
                unlimited: false,
                category: 'core',
                effect: () => {
                    this.scene.playerStats.maxHealth += 30;
                    this.scene.playerStats.health += 30;
                    if (this.scene.uiSystem) {
                        this.scene.uiSystem.updateHealthText(this.scene.playerStats.health);
                    }
                }
            },
            {
                id: 'max_mana_up',
                name: '法力强化',
                description: '最大法力值 +25',
                cost: 55,
                unlimited: false,
                category: 'core',
                effect: () => {
                    this.scene.playerStats.maxMana += 25;
                    this.scene.playerStats.mana += 25;
                }
            },
            {
                id: 'max_energy_up',
                name: '能量强化',
                description: '最大能量值 +35',
                cost: 50,
                unlimited: false,
                category: 'core',
                effect: () => {
                    this.scene.playerStats.maxEnergy += 35;
                    this.scene.playerStats.energy += 35;
                }
            },

            // === 主要属性升级 ===
            {
                id: 'strength_up',
                name: '力量训练',
                description: '力量 +2，物理伤害 +3',
                cost: 45,
                unlimited: false,
                category: 'primary',
                effect: () => {
                    this.scene.playerStats.strength += 2;
                    this.scene.playerStats.physicalDamage += 3;
                }
            },
            {
                id: 'agility_up',
                name: '敏捷训练',
                description: '敏捷 +2，暴击率 +2%',
                cost: 45,
                unlimited: false,
                category: 'primary',
                effect: () => {
                    this.scene.playerStats.agility += 2;
                    this.scene.playerStats.critChance += 0.02;
                }
            },
            {
                id: 'intelligence_up',
                name: '智力训练',
                description: '智力 +2，魔法伤害 +3',
                cost: 45,
                unlimited: false,
                category: 'primary',
                effect: () => {
                    this.scene.playerStats.intelligence += 2;
                    this.scene.playerStats.magicalDamage += 3;
                }
            },
            {
                id: 'vitality_up',
                name: '体力训练',
                description: '体力 +2，防御 +2',
                cost: 45,
                unlimited: false,
                category: 'primary',
                effect: () => {
                    this.scene.playerStats.vitality += 2;
                    this.scene.playerStats.defense += 2;
                }
            },
            {
                id: 'luck_up',
                name: '幸运护符',
                description: '幸运 +2，掉落率 +5%',
                cost: 50,
                unlimited: false,
                category: 'primary',
                effect: () => {
                    this.scene.playerStats.luck += 2;
                    this.scene.playerStats.dropRateBonus += 0.05;
                }
            },

            // === 战斗属性升级 ===
            {
                id: 'damage_up',
                name: '攻击强化',
                description: '基础伤害 +8',
                cost: 40,
                unlimited: false,
                category: 'combat',
                effect: () => {
                    this.scene.playerStats.damage += 8;
                }
            },
            {
                id: 'physical_damage_up',
                name: '物理专精',
                description: '物理伤害 +5',
                cost: 40,
                unlimited: false,
                category: 'combat',
                effect: () => {
                    this.scene.playerStats.physicalDamage += 5;
                }
            },
            {
                id: 'magical_damage_up',
                name: '魔法专精',
                description: '魔法伤害 +5',
                cost: 40,
                unlimited: false,
                category: 'combat',
                effect: () => {
                    this.scene.playerStats.magicalDamage += 5;
                }
            },
            {
                id: 'crit_chance_up',
                name: '暴击训练',
                description: '暴击率 +6%',
                cost: 60,
                unlimited: false,
                category: 'combat',
                effect: () => {
                    this.scene.playerStats.critChance += 0.06;
                }
            },
            {
                id: 'crit_damage_up',
                name: '暴击强化',
                description: '暴击伤害 +0.2倍',
                cost: 70,
                unlimited: false,
                category: 'combat',
                effect: () => {
                    this.scene.playerStats.critDamage += 0.2;
                }
            },
            {
                id: 'attack_speed_up',
                name: '攻击速度',
                description: '攻击速度 +15%',
                cost: 55,
                unlimited: false,
                category: 'combat',
                effect: () => {
                    this.scene.playerStats.attackSpeed += 0.15;
                }
            },

            // === 防御属性升级 ===
            {
                id: 'defense_up',
                name: '护甲强化',
                description: '物理防御 +5',
                cost: 45,
                unlimited: false,
                category: 'defense',
                effect: () => {
                    this.scene.playerStats.defense += 5;
                }
            },
            {
                id: 'magic_resistance_up',
                name: '魔法抗性',
                description: '魔法抗性 +5',
                cost: 45,
                unlimited: false,
                category: 'defense',
                effect: () => {
                    this.scene.playerStats.magicResistance += 5;
                }
            },
            {
                id: 'dodge_up',
                name: '闪避训练',
                description: '闪避率 +8%',
                cost: 65,
                unlimited: false,
                category: 'defense',
                effect: () => {
                    this.scene.playerStats.dodgeChance += 0.08;
                }
            },
            {
                id: 'block_up',
                name: '格挡训练',
                description: '格挡率 +7%，格挡值 +3',
                cost: 65,
                unlimited: false,
                category: 'defense',
                effect: () => {
                    this.scene.playerStats.blockChance += 0.07;
                    this.scene.playerStats.blockValue += 3;
                }
            },
            {
                id: 'damage_reduction_up',
                name: '伤害减免',
                description: '伤害减免 +4%',
                cost: 70,
                unlimited: false,
                category: 'defense',
                effect: () => {
                    this.scene.playerStats.damageReduction += 0.04;
                }
            },

            // === 恢复属性升级 ===
            {
                id: 'health_regen_up',
                name: '生命回复',
                description: '生命回复 +3/秒',
                cost: 55,
                unlimited: false,
                category: 'recovery',
                effect: () => {
                    this.scene.playerStats.healthRegen += 3;
                }
            },
            {
                id: 'mana_regen_up',
                name: '法力回复',
                description: '法力回复 +2/秒',
                cost: 50,
                unlimited: false,
                category: 'recovery',
                effect: () => {
                    this.scene.playerStats.manaRegen += 2;
                }
            },
            {
                id: 'life_steal_up',
                name: '生命偷取',
                description: '生命偷取 +5%',
                cost: 80,
                unlimited: false,
                category: 'recovery',
                effect: () => {
                    this.scene.playerStats.lifeSteal += 0.05;
                }
            },
            {
                id: 'mana_steal_up',
                name: '法力偷取',
                description: '法力偷取 +3%',
                cost: 75,
                unlimited: false,
                category: 'recovery',
                effect: () => {
                    this.scene.playerStats.manaSteal += 0.03;
                }
            },

            // === 移动属性升级 ===
            {
                id: 'speed_up',
                name: '移动速度',
                description: '移动速度 +20',
                cost: 35,
                unlimited: false,
                category: 'movement',
                effect: () => {
                    this.scene.playerStats.speed += 20;
                }
            },
            {
                id: 'move_speed_up',
                name: '速度倍数',
                description: '移动速度倍数 +12%',
                cost: 50,
                unlimited: false,
                category: 'movement',
                effect: () => {
                    this.scene.playerStats.moveSpeed += 0.12;
                }
            },
            {
                id: 'sprint_speed_up',
                name: '冲刺速度',
                description: '冲刺速度 +18%',
                cost: 55,
                unlimited: false,
                category: 'movement',
                effect: () => {
                    this.scene.playerStats.sprintSpeed += 0.18;
                }
            },

            // === 射击属性升级 ===
            {
                id: 'range_up',
                name: '射程延长',
                description: '射程 +40',
                cost: 40,
                unlimited: false,
                category: 'ranged',
                effect: () => {
                    this.scene.playerStats.range += 40;
                }
            },
            {
                id: 'accuracy_up',
                name: '精准度',
                description: '精准度 +3%',
                cost: 45,
                unlimited: false,
                category: 'ranged',
                effect: () => {
                    this.scene.playerStats.accuracy += 0.03;
                }
            },
            {
                id: 'piercing_up',
                name: '穿透子弹',
                description: '穿透 +1',
                cost: 60,
                unlimited: false,
                category: 'ranged',
                effect: () => {
                    this.scene.playerStats.piercing += 1;
                }
            },
            {
                id: 'multishot_up',
                name: '多重射击',
                description: '多重射击 +1',
                cost: 120,
                unlimited: false,
                category: 'ranged',
                effect: () => {
                    this.scene.playerStats.multishot += 1;
                }
            },
            {
                id: 'projectile_speed_up',
                name: '弹丸速度',
                description: '弹丸速度 +20%',
                cost: 50,
                unlimited: false,
                category: 'ranged',
                effect: () => {
                    this.scene.playerStats.projectileSpeed += 0.2;
                }
            },

            // === 资源属性升级 ===
            {
                id: 'exp_multiplier_up',
                name: '经验加成',
                description: '经验倍数 +20%',
                cost: 70,
                unlimited: false,
                category: 'resource',
                effect: () => {
                    this.scene.playerStats.expMultiplier += 0.2;
                }
            },
            {
                id: 'gold_multiplier_up',
                name: '金币加成',
                description: '金币倍数 +20%',
                cost: 70,
                unlimited: false,
                category: 'resource',
                effect: () => {
                    this.scene.playerStats.goldMultiplier += 0.2;
                }
            },
            {
                id: 'drop_rate_up',
                name: '掉落率',
                description: '掉落率 +8%',
                cost: 65,
                unlimited: false,
                category: 'resource',
                effect: () => {
                    this.scene.playerStats.dropRateBonus += 0.08;
                }
            },
            {
                id: 'treasure_hunting_up',
                name: '寻宝技能',
                description: '寻宝率 +12%',
                cost: 75,
                unlimited: false,
                category: 'resource',
                effect: () => {
                    this.scene.playerStats.findTreasureChance += 0.12;
                }
            },

            // === 武器专精升级 ===
            {
                id: 'weapon_damage_up',
                name: '武器伤害',
                description: '武器伤害 +6',
                cost: 50,
                unlimited: false,
                category: 'mastery',
                effect: () => {
                    this.scene.playerStats.weaponDamageBonus += 6;
                }
            },
            {
                id: 'pistol_mastery_up',
                name: '手枪专精',
                description: '手枪专精 +1',
                cost: 60,
                unlimited: false,
                category: 'mastery',
                effect: () => {
                    this.scene.playerStats.pistolMastery += 1;
                }
            },
            {
                id: 'shotgun_mastery_up',
                name: '霰弹枪专精',
                description: '霰弹枪专精 +1',
                cost: 60,
                unlimited: false,
                category: 'mastery',
                effect: () => {
                    this.scene.playerStats.shotgunMastery += 1;
                }
            },
            {
                id: 'rifle_mastery_up',
                name: '步枪专精',
                description: '步枪专精 +1',
                cost: 60,
                unlimited: false,
                category: 'mastery',
                effect: () => {
                    this.scene.playerStats.rifleMastery += 1;
                }
            },
            {
                id: 'machinegun_mastery_up',
                name: '机枪专精',
                description: '机枪专精 +1',
                cost: 60,
                unlimited: false,
                category: 'mastery',
                effect: () => {
                    this.scene.playerStats.machinegunMastery += 1;
                }
            },

            // === 特殊效果升级 ===
            {
                id: 'knockback_up',
                name: '击退强化',
                description: '击退力 +2',
                cost: 55,
                unlimited: false,
                category: 'special',
                effect: () => {
                    this.scene.playerStats.knockback += 2;
                }
            },
            {
                id: 'area_effect_up',
                name: '范围效果',
                description: '范围效果 +20%',
                cost: 70,
                unlimited: false,
                category: 'special',
                effect: () => {
                    this.scene.playerStats.areaOfEffect += 0.2;
                }
            },
            {
                id: 'status_resistance_up',
                name: '状态抗性',
                description: '状态抗性 +10%',
                cost: 65,
                unlimited: false,
                category: 'special',
                effect: () => {
                    this.scene.playerStats.statusResistance += 0.1;
                }
            },
            {
                id: 'skill_cooldown_up',
                name: '冷却缩减',
                description: '技能冷却 -8%',
                cost: 80,
                unlimited: false,
                category: 'special',
                effect: () => {
                    this.scene.playerStats.skillCooldownReduction += 0.08;
                }
            },

            // === 高级升级 ===
            {
                id: 'vampirism_up',
                name: '吸血术',
                description: '吸血 +6%',
                cost: 100,
                unlimited: false,
                category: 'advanced',
                effect: () => {
                    this.scene.playerStats.vampirism += 0.06;
                }
            },
            {
                id: 'berserker_up',
                name: '狂暴之力',
                description: '狂暴 +10%',
                cost: 90,
                unlimited: false,
                category: 'advanced',
                effect: () => {
                    this.scene.playerStats.berserker += 0.1;
                }
            },
            {
                id: 'focus_up',
                name: '专注精神',
                description: '专注 +8%',
                cost: 85,
                unlimited: false,
                category: 'advanced',
                effect: () => {
                    this.scene.playerStats.focus += 0.08;
                }
            },
            {
                id: 'combo_up',
                name: '连击系统',
                description: '连击 +1级',
                cost: 150,
                unlimited: false,
                category: 'advanced',
                effect: () => {
                    this.scene.playerStats.combo += 1;
                }
            },

            // === 生存属性升级 ===
            {
                id: 'revive_chance_up',
                name: '复活机会',
                description: '复活几率 +3%',
                cost: 200,
                unlimited: false,
                category: 'survival',
                effect: () => {
                    this.scene.playerStats.reviveChance += 0.03;
                }
            },
            {
                id: 'damage_reflection_up',
                name: '伤害反射',
                description: '伤害反射 +8%',
                cost: 120,
                unlimited: false,
                category: 'survival',
                effect: () => {
                    this.scene.playerStats.damageReflection += 0.08;
                }
            },
            {
                id: 'thorns_up',
                name: '荆棘护甲',
                description: '荆棘伤害 +3',
                cost: 90,
                unlimited: false,
                category: 'survival',
                effect: () => {
                    this.scene.playerStats.thorns += 3;
                }
            }
        ];

        // 按分类组织商品
        this.itemsByCategory = this.groupItemsByCategory();
        this.currentCategory = 'consumable';
    }

    groupItemsByCategory() {
        const categories = {};
        this.shopItems.forEach(item => {
            if (!categories[item.category]) {
                categories[item.category] = [];
            }
            categories[item.category].push(item);
        });
        return categories;
    }

    getCategoryDisplayName(category) {
        const names = {
            'consumable': '消耗品',
            'core': '核心属性',
            'primary': '主要属性',
            'combat': '战斗属性',
            'defense': '防御属性',
            'recovery': '恢复属性',
            'movement': '移动属性',
            'ranged': '射击属性',
            'resource': '资源属性',
            'mastery': '武器专精',
            'special': '特殊效果',
            'advanced': '高级属性',
            'survival': '生存属性'
        };
        return names[category] || category;
    }

    showShop() {
        console.log('显示商店，设置暂停状态');

        // 如果已经在升级状态，延迟显示商店
        if (this.scene.isUpgrading) {
            console.log('当前正在升级状态，延迟显示商店');
            this.scene.time.delayedCall(500, () => {
                this.showShop();
            });
            return;
        }

        // 设置商店暂停标志
        this.scene.isShopOpen = true;

        // 暂停物理引擎
        if (this.scene.physics) {
            this.scene.physics.pause();
        }

        // 暂停计时器
        if (this.scene.spawnEnemyTimer && !this.scene.spawnEnemyTimer.paused) {
            this.scene.spawnEnemyTimer.paused = true;
        }

        if (this.scene.waveTimer && !this.scene.waveTimer.paused) {
            this.scene.waveTimer.paused = true;
        }

        if (this.scene.countdownTimer && !this.scene.countdownTimer.paused) {
            this.scene.countdownTimer.paused = true;
        }

        this.createShopUI();
    }

    createShopUI() {
        const camera = this.scene.cameras.main;
        const centerX = camera.width / 2;
        const centerY = camera.height / 2;

        // 创建商店背景
        const shopBg = this.scene.add.rectangle(centerX, centerY, camera.width * 0.9, camera.height * 0.9, 0x000000, 0.95)
            .setScrollFactor(0)
            .setDepth(1000);

        // 商店标题
        const title = this.scene.add.text(centerX, centerY - shopBg.height / 2 + 40, '商店', {
            fontSize: '28px',
            fill: '#ffffff',
            fontStyle: 'bold'
        }).setOrigin(0.5).setScrollFactor(0).setDepth(1001);

        // 显示当前金币
        const coinText = this.scene.add.text(centerX, centerY - shopBg.height / 2 + 80, `金币: ${this.scene.gold}`, {
            fontSize: '20px',
            fill: '#FFD700'
        }).setOrigin(0.5).setScrollFactor(0).setDepth(1001);

        // 创建分类标签
        const categoryStartX = centerX - shopBg.width / 2 + 100;
        const categoryY = centerY - shopBg.height / 2 + 120;
        const categorySpacing = 100;

        this.shopUIElements = [shopBg, title, coinText];
        this.shopButtons = [];
        this.categoryButtons = [];

        // 创建分类按钮
        const categories = Object.keys(this.itemsByCategory);
        categories.forEach((category, index) => {
            const categoryX = categoryStartX + (index % 6) * categorySpacing;
            const categoryYPos = categoryY + Math.floor(index / 6) * 30;

            const categoryButton = this.scene.add.rectangle(categoryX, categoryYPos, 90, 25, 
                this.currentCategory === category ? 0x4444aa : 0x333333, 0.8)
                .setStrokeStyle(1, this.currentCategory === category ? 0x6666cc : 0x555555)
                .setScrollFactor(0)
                .setDepth(1001);

            const categoryText = this.scene.add.text(categoryX, categoryYPos, 
                this.getCategoryDisplayName(category), {
                fontSize: '12px',
                fill: this.currentCategory === category ? '#ffffff' : '#cccccc'
            }).setOrigin(0.5).setScrollFactor(0).setDepth(1002);

            categoryButton.setInteractive();
            categoryButton.on('pointerdown', () => {
                this.currentCategory = category;
                this.refreshShopUI();
            });

            this.categoryButtons.push({ button: categoryButton, text: categoryText, category: category });
            this.shopUIElements.push(categoryButton, categoryText);
        });

        // 创建商品列表
        this.createItemList();

        // 创建关闭按钮
        const closeButton = this.scene.add.rectangle(centerX + shopBg.width / 2 - 50, 
            centerY - shopBg.height / 2 + 40, 80, 30, 0x666666, 0.8)
            .setStrokeStyle(1, 0x888888)
            .setScrollFactor(0)
            .setDepth(1001);

        const closeText = this.scene.add.text(centerX + shopBg.width / 2 - 50, 
            centerY - shopBg.height / 2 + 40, '关闭', {
            fontSize: '16px',
            fill: '#ffffff'
        }).setOrigin(0.5).setScrollFactor(0).setDepth(1002);

        closeButton.setInteractive();
        closeButton.on('pointerdown', () => {
            this.hideShop();
        });

        this.shopUIElements.push(closeButton, closeText);
    }

    createItemList() {
        const camera = this.scene.cameras.main;
        const centerX = camera.width / 2;
        const centerY = camera.height / 2;

        // 获取当前分类的商品
        const currentItems = this.itemsByCategory[this.currentCategory] || [];
        
        // 商品列表区域
        const itemStartY = centerY - 100;
        const itemSpacing = 50;
        const itemsPerPage = 8;
        const startIndex = 0; // 简化版本，不实现分页

        currentItems.slice(startIndex, startIndex + itemsPerPage).forEach((item, index) => {
            const itemY = itemStartY + index * itemSpacing;
            const isAvailable = item.unlimited || !this.purchasedItems.has(item.id);
            const canAfford = this.scene.gold >= item.cost;

            // 商品背景
            const itemBg = this.scene.add.rectangle(centerX, itemY, camera.width * 0.8, 45, 
                isAvailable ? (canAfford ? 0x333333 : 0x444444) : 0x666666, 0.7)
                .setScrollFactor(0)
                .setDepth(1001);

            // 商品名称
            const itemName = this.scene.add.text(centerX - camera.width * 0.35, itemY, item.name, {
                fontSize: '16px',
                fill: isAvailable ? '#ffffff' : '#888888'
            }).setScrollFactor(0).setDepth(1002);

            // 商品描述
            const itemDesc = this.scene.add.text(centerX - camera.width * 0.1, itemY, item.description, {
                fontSize: '14px',
                fill: isAvailable ? '#cccccc' : '#666666'
            }).setScrollFactor(0).setDepth(1002);

            // 价格
            const costText = this.scene.add.text(centerX + camera.width * 0.25, itemY, `${item.cost}`, {
                fontSize: '16px',
                fill: canAfford ? '#FFD700' : '#888888'
            }).setScrollFactor(0).setDepth(1002);

            // 购买按钮
            if (isAvailable && canAfford) {
                const buyButton = this.scene.add.rectangle(centerX + camera.width * 0.35, itemY, 60, 30, 0x4444aa, 0.8)
                    .setStrokeStyle(1, 0x6666cc)
                    .setScrollFactor(0)
                    .setDepth(1001);

                const buyText = this.scene.add.text(centerX + camera.width * 0.35, itemY, '购买', {
                    fontSize: '14px',
                    fill: '#ffffff'
                }).setOrigin(0.5).setScrollFactor(0).setDepth(1002);

                buyButton.setInteractive();
                buyButton.on('pointerdown', () => {
                    this.buyItem(item);
                });

                this.shopButtons.push({ button: buyButton, text: buyText, item: item });
                this.shopUIElements.push(buyButton, buyText);
            }

            this.shopUIElements.push(itemBg, itemName, itemDesc, costText);
        });
    }

    refreshShopUI() {
        // 清除现有UI
        this.shopUIElements.forEach(element => {
            if (element && element.destroy) {
                element.destroy();
            }
        });
        this.shopUIElements = [];
        this.shopButtons = [];
        this.categoryButtons = [];

        // 重新创建UI
        this.createShopUI();
    }

    buyItem(item) {
        if (this.scene.gold >= item.cost) {
            // 扣除金币
            this.scene.gold -= item.cost;
            
            // 应用物品效果
            item.effect();
            
            // 如果不是无限购买，标记为已购买
            if (!item.unlimited) {
                this.purchasedItems.add(item.id);
            }
            
            // 更新UI
            this.refreshShopUI();
            
            // 更新游戏UI
            if (this.scene.uiSystem) {
                this.scene.uiSystem.updateAllUI();
            }
            
            console.log(`购买了 ${item.name}，剩余金币: ${this.scene.gold}`);
        }
    }

    hideShop() {
        console.log('隐藏商店，恢复游戏状态');
        
        // 清除所有商店UI元素
        this.shopUIElements.forEach(element => {
            if (element && element.destroy) {
                element.destroy();
            }
        });
        this.shopUIElements = [];
        this.shopButtons = [];
        this.categoryButtons = [];
        
        // 恢复游戏状态
        this.scene.isShopOpen = false;
        
        // 恢复物理引擎
        if (this.scene.physics) {
            this.scene.physics.resume();
        }

        // 恢复计时器
        if (this.scene.spawnEnemyTimer && this.scene.spawnEnemyTimer.paused) {
            this.scene.spawnEnemyTimer.paused = false;
        }

        if (this.scene.waveTimer && this.scene.waveTimer.paused) {
            this.scene.waveTimer.paused = false;
        }

        if (this.scene.countdownTimer && this.scene.countdownTimer.paused) {
            this.scene.countdownTimer.paused = false;
        }

        console.log('商店关闭，游戏恢复');
    }
}